package datastructure.array;

/**
 *http://www.geeksforgeeks.org/archives/2398
 *
 *Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements.
 *
 *
 * @author Lei Zhang
 */
public class LeftRotateArray {
  public static void leftRotateArrayByOne(int[] arr) {
    int tmp = arr[0];
    for (int i = 0; i < arr.length - 1; i++) {
      arr[i] = arr[i + 1];
    }
    arr[arr.length - 1] = tmp;
  }

  public static void leftRotateArrayByD(int[] arr, int D) {
    for (int i = 0; i < D; i++) {
      leftRotateArrayByOne(arr);
    }
  }

  public static void main(String args[]) {

    int[] arr = {1,
      2,
      3,
      4,
      5,
      6,
      7};

    leftRotateArrayByD(arr, 2);

    for (int i = 0; i < arr.length; i++) {
      System.out.println(arr[i]);
    }
  }
}
